﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Net.Mime;
using DAL;
using System.Collections.Generic;
using System.ComponentModel;
using Telerik.Web.UI;
using System.Globalization;



public partial class Kho_UserControl_uc_SoanHang : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            InitData();
        }
    }

    private void InitData()
    {
        lblAlerting.Text = string.Empty;
        txtNgay.Text = DateTime.Now.ToString("dd/MM/yyyy");
        hdfID.Value = "-1";
        GetBuoi();
    }
    private void GetBuoi()
    {
        try
        {
            CateRouteBO cate = new CateRouteBO();
            List<ZD_PRC_ZD_CATE_BUOI_GETBYIDResult> lst = new List<ZD_PRC_ZD_CATE_BUOI_GETBYIDResult>();
            lst = cate.BuoiGet(-1);
            if (lst != null)
            {
                ddlBUOI.DataSource = lst;
                ddlBUOI.DataTextField = "TENBUOI";
                ddlBUOI.DataValueField = "BUOIID";
                ddlBUOI.DataBind();

                ListItem lstParent = new ListItem("--Chọn--", "0");
                ddlBUOI.Items.Insert(0, lstParent);
                ddlBUOI.SelectedIndex = ddlBUOI.Items.IndexOf(lstParent);
            }
        }
        catch
        {
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        lblAlerting.Text = string.Empty;
        DateTime dt = new DateTime();
        try
        {
            dt = DateTime.ParseExact(txtNgay.Text.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
            hdfDateTime.Value = txtNgay.Text.Trim();
        }
        catch
        {
            lblAlerting.Text = "Bạn chưa nhập ngày hoặc ngày không đúng!";
            return;
        }
        if (int.Parse(ddlBUOI.SelectedValue) <= 0)
        {
            lblAlerting.Text = "Bạn chưa chọn buổi!";
            return;
        }
        hdfBUOIID.Value = ddlBUOI.SelectedValue;
        DeliveryBO del = new DeliveryBO();
        List<ZD_PRC_ZD_DELIVERY_KHO_VIEWResult> result = new List<ZD_PRC_ZD_DELIVERY_KHO_VIEWResult>();
        result = del.Delivery_SO_Detail_Kho_View(dt, int.Parse(ddlBUOI.SelectedValue));
        grdList.DataSource = result;
        grdList.DataBind();
    }


    protected void grdList_RowEditing(object sender, GridViewEditEventArgs e)
    {
        lblAlerting.Text = string.Empty;
        grdList.EditIndex = e.NewEditIndex;
        hdfID.Value = grdList.DataKeys[e.NewEditIndex].Value.ToString();
        string Link = "../kview/sv_" + hdfDateTime.Value.Replace("/", "") + "_" + hdfBUOIID.Value + "_" + hdfID.Value;
        Response.Redirect(Link);

    }

}
